class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        l = len(s)
        if l==0:
            return 0
        d = {}
        f = [1] * l
        d[s[0]] = 0
        for i in range(1,l):
            if s[i] not in d:
                f[i] = f[i-1]+1
            else:
                ds = i-d[s[i]]
                if ds <= f[i-1]:
                    f[i] =ds
                else:
                    f[i]=  f[i-1]+1
            d[s[i]] = i
        return max(f)

b="abcabcbb"
s = Solution()
a =s.lengthOfLongestSubstring(b)
print(a)